package com.zzyl.nursing.controller.member;

import java.util.List;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.nursing.service.IFamilyMemberService;

/**
 * 老人家属Controller
 * 
 * @author alexis
 * @date 2024-11-10
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属管理")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        // 调用Service层接口完成登录
        LoginVo loginVo = familyMemberService.saveFamilyMember(userLoginRequestDto);
        return R.ok(loginVo);
    }

    @PostMapping("/add")
    public R add(@RequestBody FamilyMemberElder familyMemberElder){
        familyMemberService.addMemberElder(familyMemberElder);
        return R.ok();
    }

    @GetMapping("/my")
    public R<List<FamilyMemberElderVo>> getMyElders(){
        List<FamilyMemberElderVo> familyMemberElderVos = familyMemberService.selectMyElders();
        return R.ok(familyMemberElderVos);
    }

    @GetMapping("/list-by-page")
    public R<List<FamilyMemberElderListVo>> getFamilyMemberElderList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize) {
        List<FamilyMemberElderListVo> list = familyMemberService.getFamilyMemberElderList(pageNum, pageSize);

        return R.ok(list);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return familyMemberService.queryDevicePropertyStatus(request);
    }

       @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(@ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
            @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
            @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
            @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {

        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return success(list);
    }

        @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(@ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
            @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
            @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
            @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {

        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
        return success(list);
    }
}
